package generator;

import java.io.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author Jose Carlos Gutierrez
 */
public class Escritor {

    private PrintWriter salida;

    public Escritor(String file){
        try {
            this.salida = new PrintWriter(new FileOutputStream(new File(file)));
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
    }

    public void escribir(String linea){
        salida.println(linea);
    }

    public void cerrar(){
        salida.flush();
        salida.close();
    }

    public static Vector<String> leer(String path){        
        try {
            Vector<String> lineas = new Vector<String>();
            FileInputStream stream = new FileInputStream(new File(path));
            FileReader d; InputStreamReader i;
            Scanner scan = new Scanner(stream);
            while(scan.hasNext()){
                String linea = scan.nextLine();
                lineas.addElement(linea);
            }
            return lineas;
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Escritor.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
